package com.bing.tag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;

/**
 * Created by kai on 2014/4/14.
 */
public class RedirectTag extends TagSupport {
    private String url;

    public void setUrl(String url) {
        this.url = url;
    }

    @Override
    public int doEndTag() throws JspException {

        HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        try {
            System.out.println("requestUrl:" +request.getRequestURL());
            response.sendRedirect(url);
        } catch (java.io.IOException ex) {
            throw new JspTagException(ex.toString(), ex);
        }

        return SKIP_PAGE;
    }
}
